home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / reqtoolsdev.lha / ReqTools / demo / demo.e < prev    next >
Text File  |  1996-05-23  |  12KB  |  345 lines

  1. /************************************************
  2. *                                        *
  3. *  reqtools.library (V38)                *
  4. *                                        *
  5. *  Release 2.5                           *
  6. *                                        *
  7. *  (c) 1991-1994 Nico François           *
  8. *      1995-1996 Magnus Holmgren                *
  9. *                                        *
  10. *  demo.e                                *
  11. *                         *
  12. * Translated by: Marco Talamelli         *
  13. *                         *
  14. * EMail: Marco_Talamelli@amp.flashnet.it    *
  15. *                                        *
  16. * This source is public domain in all respects. *
  17. *                                        *
  18. ************************************************/
  19.  
  20. MODULE     'reqtools',
  21.     'graphics/text',
  22.     'libraries/reqtools',
  23.     'utility/tagitem',
  24.     'intuition/intuition',
  25.     'utility/hooks'
  26.  
  27. CONST FILEREQ=0,REQINFO=1
  28.  
  29. PROC main()
  30.  
  31. DEF     scrmodereq : PTR TO rtscreenmoderequester,filereq:PTR TO rtfilerequester,
  32.     fontreq:PTR TO rtfontrequester,color,autoscroll,
  33.     buf[120]:STRING,flist:PTR TO rtfilelist,filename[34]:STRING,
  34.     ret,longnum,response
  35.  
  36.   IF reqtoolsbase:=OpenLibrary('reqtools.library',37)
  37.  
  38.     RtEZRequestA('ReqTools 2.0 Demo\n'+
  39.                  '~~~~~~~~~~~~~~~~~\n'+
  40.                      '''reqtools.library'' offers several\n'+
  41.                      'different types of requesters:',
  42.                      'Let\as see them', NIL, NIL,NIL)
  43.  
  44.     RtEZRequestA('NUMBER 1:\nThe larch :-)', 'Be serious!',NIL, NIL, NIL)
  45.  
  46.     RtEZRequestA('NUMBER 1:\nString requester\nfunction: RtGetStringA()',
  47.                      'Show me', NIL,NIL, NIL)
  48.  
  49.     StrCopy(buf,'A bit of text',ALL)
  50.  
  51.     IF RtGetStringA(buf, 127, 'Enter anything:', NIL, 0)=NIL
  52.         RtEZRequestA('You entered nothing :-(', 'I\am sorry', NIL,NIL, NIL)
  53.     ELSE
  54.         RtEZRequestA('You entered this string:\n \a\s\a.','So I did', NIL, [buf], NIL)
  55.     ENDIF
  56.  
  57.     ret := RtGetStringA(buf, 127, 'Enter anything:', NIL,
  58.             [RTGS_GADFMT,' _Ok |New _2.0 feature!|_Cancel',
  59.             RTGS_TEXTFMT,
  60. 'These are two new features of ReqTools 2.0:\nText above the entry gadget and more than\none response gadget.',
  61.                 RT_UNDERSCORE, "_",NIL])
  62.  
  63.     IF (ret = 2) THEN RtEZRequestA('Yep, this is a new\nReqTools 2.0 feature!',
  64.                          'Oh boy!', NIL,NIL, NIL)
  65.  
  66.     ret := RtGetStringA(buf, 127, 'Enter anything:', NIL,
  67.                  [RTGS_GADFMT, ' _Ok |_Abort|_Cancel',
  68.                  RTGS_TEXTFMT,
  69. 'New is also the ability to switch off the\nbackfill pattern.  You can also center the\ntext above the entry gadget.\nThese new features are also available in\nthe RtGetLongA() requester.',
  70.                  RTGS_BACKFILL, FALSE,
  71.                  RTGS_FLAGS, GSREQF_CENTERTEXT OR GSREQF_HIGHLIGHTTEXT,
  72.                  RT_UNDERSCORE, "_",NIL])
  73.  
  74.     IF (ret = 2) THEN RtEZRequestA('What!! You pressed abort!?!\nYou must be joking :-)',
  75.                          'Ok, Continue', NIL, NIL, NIL)
  76.  
  77.  
  78.     RtEZRequestA('NUMBER 2:\nNumber requester\nfunction: RtGetLongA()',
  79.                      'Show me', NIL, NIL, NIL)
  80.  
  81.     IF RtGetLongA({longnum}, 'Enter a number:', NIL,
  82.                          [RTGL_SHOWDEFAULT, FALSE,
  83.                          RTGL_MIN, 0, RTGL_MAX, 666,NIL])=FALSE
  84.  
  85.         RtEZRequestA('You entered nothing :-(','I\am sorry', NIL,NIL, NIL)
  86.     ELSE
  87.         RtEZRequestA('The number you entered was:\n\d\s',
  88.      'So it was', NIL,
  89.         IF (longnum = 666) THEN [longnum, ' (you devil! :)'] ELSE  [longnum,'!'], NIL)
  90.     ENDIF
  91.  
  92.     RtEZRequestA('NUMBER 3:\nMessage requester, the requester\n'+
  93.             'you\ave been using all the time!\nfunction: RtEZRequestA()',
  94.                      'Show me more', NIL,NIL, NIL)
  95.  
  96.     RtEZRequestA('Simplest usage: some body text and\na single centered gadget.',
  97.                      'Got it', NIL,NIL, NIL)
  98.  
  99.     WHILE RtEZRequestA('You can also use two gadgets to\n'+
  100.         'ask the user something.\n'+
  101.         'Do you understand?', 'Of course|Not really',
  102.         NIL, NIL,NIL)=FALSE DO RtEZRequestA('You are not one of the'+
  103.         ' brightest are you?\nWe\all try again...','Ok', NIL, NIL,NIL)
  104.  
  105.     RtEZRequestA('Great, we\all continue then.', 'Fine', NIL, NIL,NIL)
  106.  
  107.     response := RtEZRequestA('You can also put up a requester with\n'+
  108.                     'three choices.\n'+
  109.                     'How do you like the demo so far ?',
  110.                     'Great|So so|Rubbish', NIL, NIL,NIL)
  111.     SELECT response
  112.         CASE 0
  113.             RtEZRequestA('Too bad, I really hoped you\nwould like it better.',
  114.                              'So what', NIL, NIL,NIL)
  115.         CASE 1
  116.             RtEZRequestA('I\am glad you like it so much.', 'Fine', NIL, NIL,NIL)
  117.         CASE 2
  118.             RtEZRequestA('Maybe if you run the demo again\n'+
  119.                      'you\all REALLY like it.',
  120.                      'Perhaps', NIL, NIL,NIL)
  121.     ENDSELECT
  122.  
  123.     ret := RtEZRequestA('The number of responses is not limited to three\n'+
  124.                   'as you can see.  The gadgets are labeled with\n'+
  125.                   'the return code from RtEZRequestA().\n'+
  126.                   'Pressing Return will choose 4, note that\n'+
  127.                   '4\as button text is printed in boldface.',
  128.                   '1|2|3|4|5|0', NIL, NIL,
  129.                   [RTEZ_DEFAULTRESPONSE, 4,NIL])
  130.  
  131.     RtEZRequestA('You picked \d.', 'How true', NIL, [ret], NIL)
  132.  
  133.     RtEZRequestA('New for Release 2.0 of ReqTools (V38) is\n'+
  134.               'the possibility to define characters in the\n'+
  135.               'buttons as keyboard shortcuts.\n'+
  136.               'As you can see these characters are underlined.\n'+
  137.               'Pressing shift while still holding down the key\n'+
  138.               'will cancel the shortcut.\n'+
  139.               'Note that in other requesters a string gadget may\n'+
  140.               'be active.  To use the keyboard shortcuts there\n'+
  141.               'you have to keep the Right Amiga key pressed down.',
  142.               '_Great|_Fantastic|_Swell|Oh _Boy',
  143.               NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  144.  
  145.     RtEZRequestA('You may also use E-style formatting codes in the body text.\n'+
  146.         'Like this:\n\n\aThe number \\d is written \\s\a. will give:\n\n'+
  147.         'The number \d is written \s.\n\n'+
  148.         'if you also pass 5 and ''"five"'' to RtEZRequestA().',
  149.         '_Proceed', NIL, [5, 'five'],[RT_UNDERSCORE, "_",NIL])
  150.  
  151.  
  152.     IF (RtEZRequestA('It is also possible to pass extra IDCMP flags\n'+
  153.                   'that will satisfy RtEZRequestA(). This requester\n'+
  154.                   'has had IDCMP_DISKINSERTED passed to it.\n'+
  155.                   '(Try inserting a disk).',
  156.                   '_Continue', NIL, NIL,[ RT_IDCMPFLAGS, IDCMP_DISKINSERTED,
  157.                 RT_UNDERSCORE, "_",NIL]) AND IDCMP_DISKINSERTED)
  158.         RtEZRequestA('You inserted a disk.', 'I did', NIL, NIL,NIL)
  159.  
  160.     ELSE
  161.         RtEZRequestA('You used the \aContinue\a gadget\n'+
  162.                      'to satisfy the requester.', 'I did', NIL, NIL,NIL)
  163.     ENDIF
  164.  
  165.     RtEZRequestA('Finally, it is possible to specify the position\n'+
  166.                  'of the requester.\n'+
  167.                  'E.g. at the top left of the screen, like this.\n'+
  168.                  'This works for all requesters, not just rtEZRequest()!',
  169.                  'Amazing', NIL,NIL,
  170.                 [RT_REQPOS, REQPOS_TOPLEFTSCR,RT_UNDERSCORE, "_",NIL])
  171.  
  172.     RtEZRequestA('Alternatively, you can center the\n'+
  173.                   'requester on the screen.\n'+
  174.                   'Check out \areqtools.doc\a for all the possibilities.',
  175.                   'I\all do that', NIL, NIL,[RT_REQPOS, REQPOS_CENTERSCR,NIL])
  176.  
  177.     RtEZRequestA('NUMBER 4:\nFile requester\n'+
  178.                   'function: RtFileRequestA()',
  179.                   '_Demonstrate', NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  180.  
  181.     IF (filereq := RtAllocRequestA(RT_FILEREQ, NIL))
  182.  
  183.         filename[0] := 0
  184.         IF RtFileRequestA(filereq, filename, 'Pick a file',0)
  185.  
  186.             RtEZRequestA('You picked the file:\n\s\nin directory:\n\a\s\a',
  187.                     'Right', NIL, [filename, filereq.dir], NIL)
  188.         ELSE
  189.             RtEZRequestA('You didn\at pick a file.', 'No', NIL, NIL,NIL)
  190.  
  191.         ENDIF
  192.  
  193.         RtEZRequestA('The file requester has the ability\n'+
  194.                   'to allow you to pick more than one\n'+
  195.                   'file (use Shift to extend-select).\n'+
  196.                   'Note the extra gadgets you get.',
  197.                   '_Interesting', NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  198.  
  199.         flist := RtFileRequestA(filereq, filename, 'Pick some files',
  200.                         [RTFI_FLAGS, FREQF_MULTISELECT,NIL])
  201.         IF (flist) THEN;
  202.             RtEZRequestA('You selected some files, this is\n'+
  203.                      'the first one:\n\a\s\a\n'+
  204.                      'All the files are returned as a linked\n'+
  205.                      'list (see demo.e and reqtools.m).',
  206.                      'Aha', NIL, [flist.name], NIL)
  207.  
  208.  
  209.         RtFreeRequest(filereq)
  210.     ELSE
  211.         RtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL, NIL)
  212.  
  213.     ENDIF
  214.  
  215.     RtEZRequestA('The file requester can be used\n'+
  216.               'as a directory requester as well.',
  217.               'Let\as _see that', NIL, NIL, [RT_UNDERSCORE, "_"])
  218.  
  219.     IF (filereq := RtAllocRequestA(RT_FILEREQ, NIL))
  220.         IF (RtFileRequestA(filereq, filename, 'Pick a directory',
  221.                     [RTFI_FLAGS, FREQF_NOFILES]))
  222.  
  223.             RtEZRequestA('You picked the directory:\n\a\s\a',
  224.                      'Right', NIL, [filereq.dir], NIL)
  225.         ELSE
  226.             RtEZRequestA('You didn\at pick a directory.', 'No', NIL, NIL,NIL)
  227.  
  228.         RtFreeRequest(filereq)
  229.         ENDIF
  230.     ELSE
  231.         RtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL,NIL)
  232.     ENDIF
  233.  
  234.     RtEZRequestA('NUMBER 5:\nFont requester\n'+
  235.              'function: RtFontRequestA()',
  236.              'Show', NIL, NIL,NIL)
  237.  
  238.     IF (fontreq := RtAllocRequestA(RT_FONTREQ, NIL))
  239.  
  240.         fontreq.flags := FREQF_STYLE OR FREQF_COLORFONTS
  241.  
  242.         IF (RtFontRequestA(fontreq, 'Pick a font',0))
  243.  
  244.             RtEZRequestA('You picked the font:\n\a\s\a\nwith size:\n\a\d\a',
  245.                     'Right', NIL,
  246.                     [fontreq.attr.name, fontreq.attr.ysize], NIL)
  247.         ELSE
  248.             RtEZRequestA('You canceled.\nWas there no font you liked ?',
  249.                      '_Nope', NIL, NIL, [RT_UNDERSCORE,"_",NIL])
  250.         ENDIF
  251.  
  252.         RtFreeRequest(fontreq)
  253.     ELSE
  254.         RtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL,NIL)
  255.     ENDIF
  256.  
  257.     RtEZRequestA('NUMBER 6:\nPalette requester\n'+
  258.                  'function: RtPaletteRequestA()',
  259.                  '_Proceed', NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  260.  
  261.     color := RtPaletteRequestA('Change palette', NIL, NIL)
  262.  
  263.     IF (color = -1)
  264.         RtEZRequestA('You canceled.\nNo nice colors to be picked ?',
  265.                          'Nah', NIL, NIL,NIL)
  266.     ELSE
  267.         RtEZRequestA('You picked color number \d.', 'Sure did',
  268.                          NIL, [color], NIL)
  269.     ENDIF
  270.  
  271.     RtEZRequestA('NUMBER 7: (ReqTools 2.0)\n'+
  272.                   'Volume requester\n'+
  273.                   'function: RtFileRequestA() with\n'+
  274.                   '          RTFI_VOLUMEREQUEST tag.',
  275.                   '_Show me', NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  276.  
  277.     IF (filereq := RtAllocRequestA(RT_FILEREQ, NIL))
  278.  
  279.         IF (RtFileRequestA(filereq, NIL, 'Pick a volume',[RTFI_VOLUMEREQUEST, NIL]))
  280.  
  281.             RtEZRequestA('You picked the volume:\n\a\s\a',
  282.                     'Right', NIL, [filereq.dir], NIL)
  283.         ELSE
  284.             RtEZRequestA('You didn\at pick a volume.', 'I did not', NIL, NIL,NIL)
  285.         ENDIF
  286.  
  287.         RtFreeRequest(filereq)
  288.     ELSE
  289.         RtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL,NIL)
  290.     ENDIF
  291.     RtEZRequestA('NUMBER 8: (ReqTools 2.0)\n'+
  292.               'Screen mode requester\n'+
  293.               'function: rtScreenModeRequest()\n'+
  294.               'Only available on Kickstart 2.0!',
  295.               '_Proceed', NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  296.  
  297.     IF KickVersion(38)=FALSE
  298.         RtEZRequestA('Your Amiga doesn\at seem to have\n'+
  299.                      'Kickstart 2.0 in ROM so I am not\n'+
  300.                      'able to show you the Screen mode\n'+
  301.                      'requester.\n'+
  302.                      'So upgrade to 2.0 *now* :-)',
  303.                      '_Allright', NIL, NIL, [RT_UNDERSCORE, "_",NIL])
  304.     ELSE
  305.         IF scrmodereq := RtAllocRequestA(RT_SCREENMODEREQ, NIL)
  306.  
  307.             IF (RtScreenModeRequestA(scrmodereq, 'Pick a screen mode:',
  308.                             [RTSC_FLAGS, SCREQF_DEPTHGAD OR
  309.                                      SCREQF_SIZEGADS OR
  310.                                      SCREQF_AUTOSCROLLGAD OR
  311.                                      SCREQF_OVERSCANGAD,
  312.                                      NIL]))
  313.  
  314.                 autoscroll:=IF scrmodereq.autoscroll THEN 'On' ELSE 'Off'
  315.  
  316.                 RtEZRequestA('You picked this mode:\n'+
  317.                             'ModeID  : $\h\n'+
  318.                             'Size    : \d x \d\n'+
  319.                             'Depth   : \d\n'+
  320.                             'Overscan: \d\n'+
  321.                             'AutoScroll \s',
  322.                             'Right', NIL,
  323.                             [scrmodereq.displayid,
  324.                             scrmodereq.displaywidth,
  325.                             scrmodereq.displayheight,
  326.                             scrmodereq.displaydepth,
  327.                             scrmodereq.overscantype,
  328.                             autoscroll], NIL)
  329.             ELSE
  330.                 RtEZRequestA('You didn\at pick a screen mode.', 'Nope', NIL, NIL,NIL)
  331.  
  332.             RtFreeRequest(scrmodereq)
  333.             ENDIF
  334.         ELSE
  335.             RtEZRequestA('Out of memory!', 'Oh boy!', NIL, NIL, NIL)
  336.         ENDIF
  337.         RtEZRequestA('That\as it!\nHope you enjoyed the demo',
  338.                 '_Sure did', NIL, NIL,[    RT_UNDERSCORE, "_",NIL])
  339.     ENDIF
  340.     CloseLibrary(reqtoolsbase)
  341.   ELSE
  342.     WriteF('Could not open reqtools.library!\n')
  343.   ENDIF
  344. ENDPROC
  345.